package com.bestcem.xm.txtanls.grpc.client;

import com.zy.dp.proto.strontium.v1.AnalyzeSentimentRequest;
import com.zy.dp.proto.strontium.v1.AnalyzeSentimentResponse;
import com.zy.dp.proto.strontium.v1.SentimentEndpointGrpc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 大数据 文本情感分析 模块相关rpc接口客户端
 *
 * @author gy.liu
 * @version 1.0
 * @date 2021/5/21 14:21
 */
@Slf4j
@Service
public class SentimentGrpcService {

    //@GrpcClient(GrpcClientNames.DP)
    //private SentimentEndpointGrpc.SentimentEndpointBlockingStub sentimentEndpointBlockingStub;

    @Resource(name = "txtanlsBPSentimentClient")
    private SentimentEndpointGrpc.SentimentEndpointBlockingStub sentimentEndpointBlockingStub;

    /**
     * 大数据文本情感分析
     *
     * @param text     待分析文本列表
     * @param business 行业
     * @return 分析结果
     * @author gy.liu
     * @date 2021/5/21 14:21
     */
    public AnalyzeSentimentResponse getSentiment(List<String> text, String business) {
        AnalyzeSentimentRequest.Builder builder = AnalyzeSentimentRequest.newBuilder();
        builder.setBusiness(business);
        builder.setModelVersion("latest");
        builder.addAllTexts(text);
        return sentimentEndpointBlockingStub.analyzeSentiment(builder.buildPartial());
    }
}
